$(function () {
    $("#stutable").bootstrapTable({
        //请求方式  get请求中文会乱码，建议使用post请求
        method: "post",
        //请求头部的设置
        contentType: "application/json",
        //url
        url: "/stu",
        //设置交替行样式
        striped: true,
        //初始显示页号
        pageNumber: 1,
        //设置表格高度
        //height: 350,
        //是否显示分页
        pagination: true,
        //设置是服务端分页还是客户端分页
        sidePagination: "server",
        //页大小
        pageSize: 2,
        //分页列表
        pageList: [2,4,6,8],
        //上传到服务端的参数
        queryParams: function (params) {
            return {
                // 计算页号(当前页)
                page: (params.offset / params.limit) + 1,
                // 计算页大小
                pageNum: params.limit,
                ename:document.getElementById("ename").value,
                job:document.getElementById("job").value,
                deptno:document.getElementById("deptno").value
            };

        },
        // 定义列名
        columns: [
            {title: "编号", field: "empno", align: "center"},
            {title: "姓名", field: "ename", align: "center"},
            {title: "性别", field: "job", align: "center"},
            {title: "入职日期", field: "hiredate", align: "center"},
            {title: "薪水", field: "sal", align: "center"},
            {title: "部门", field: "deptno", align: "center"},
            {title: "操作", field: "empno", align: "center",
                formatter: function (value, row, index) {
                    var btn1 = "<button onclick='update()' class=\"btn btn-primary btn-sm\" data-toggle=\"modal\" onclick=\"editRow(this,"+row.empno+")\" data-target=\"#myModal\">编辑</button>";
                    var btn2 = "<button class=\"btn btn-warning  btn-sm\">删除</button>";
                    return btn1 + "&nbsp;" + btn2;
                }
            }
        ]
    })

    $("#submit_select").click(function () {
        $("#stutable").bootstrapTable("refresh");
    })
})

function sc(empno) {
    $.ajax({
        type:"delete",
        dataType:"json",
        url:"/stu/sc"+empno,
        success:function (data) {
            if (data!=0){
                $("#myModal").modal("hide");//隐藏模态框
                $("#stutable").bootstrapTable('refresh');
            }
        }
    })
}